<?php

namespace App;

class PublicGemsLog extends Model
{
    protected $table = 'public_gems_log';

    public function agentName($agent_id)
    {
        if ($this->type == 2) {
        	$agent = Agent::where(['id' => $agent_id])->first();
        	return $agent ? $agent->realname : '';
        } else if ($this->type == 3) {
            $user = User::where(['id' => $agent_id])->first();
            return $user->nickname ? $user->nickname: base64_decode($user->name);
        } else if ($this->type == 1) {
            $agent = Agent::where(['id' => $agent_id])->first();
            return $agent ? $agent->realname : '';
        }
    }

    public function sendName()
    {
    	if ($this->send_id) {
			$agent = Agent::where(['id' => $this->send_id])->first();
			return $agent ? $agent->realname : '';
    	} else {
    		return '平台';
    	}
    }

    public function userName()
    {
        if ($this->type == 2) {
            $agent = Agent::where(['id' => $this->accept_id])->first();
            return $agent ? $agent->realname : '';
        } else if ($this->type == 3) {
            $user = User::where(['id' => $this->accept_id])->first();
            return base64_decode($user->name);
        }
    }
}    